# Makefile for YANG-based NETCONF Manager Application
#  
#   yangcli directory

############### SOURCE PROFILE ##############################

SUBDIR_NM=yangcli
SUBDIR_CPP=-I../../../libtecla

############### TARGET PROFILE ##############################

TARGET=$(TBASE)/$(SUBDIR_NM)
BIN_INST=$(TBASE)/bin
REAL_INST=$(DESTDIR)$(PREFIX)/bin
PROG=yangcli

ifndef MAC
LN_EXTRA=-Wl,-utputs -Wl,-utparm -Wl,-utigetnum -Wl,-utigetstr -Wl,-usetupterm
endif

##################### LIBRARIES ########################

# The order of these LIBS matters!
#
# If the linker can't find external symbols you know should
# be there and you get an Unresolved External error 
#   file foo : unresolved external to bar
# Then put the library that contains foo BEFORE the one
# that contains bar. 

# this breaks ubuntu build cannot find libcrypto
#LCRYPTO=-L/lib
# $(LCRYPTO) -lcrypto 
## LINUX

ifdef MAC
LFIRST=-L/sw/lib/x86_64
else
LFIRST=
endif

DLIBS =	-L../../target/lib -lmgr -lncx \
	-L../../../libtecla -ltecla \
	$(LFIRST) -L$(PREFIX)/lib -L/usr/local/lib -lxml2 -lncurses -lssh2 \
	-L$(PREFIX)/lib -lz -lm

ifndef FREEBSD
DLIBS += -ldl
endif

# SLIBS used only if FULL_STATIC=1 is set in build
# (no used anymore in debian packaging)
SLIBS = -L../../target/lib -lmgr -lncx \
	-L$(PREFIX)/lib -lxml2 \
	-l:$(PREFIX)/lib/libssh2.a \
	-L$(PREFIX)/lib -lgpg-error \
	-l:../../../libtecla/libtecla.a \
	-L$(PREFIX)/lib -lncurses -lz -lm

ifdef DEBIAN
SLIBS += -L$(PREFIX)/lib -lgcrypt
else
SLIBS += -l:/lib/libgcrypt.a
endif


# set FULL_STATIC=1 to force complete shared libraries
# except libxml2 which is always installed on linux
# this does not work yet for fedora 12; a libtecla
# file is not resolving a few symbols from libncurses.a
ifdef FULL_STATIC
MYLIBS=$(SLIBS)
else
MYLIBS=$(DLIBS)
endif


LIBTARGS= $(LBASE)/libmgr.a $(LBASE)/libncx.$(LIBNCXSUFFIX)

############################# MAKE RULES ##################
ifdef DEVELOPER
all:
else
all: yangcli
endif

#################### PLATFORM DEFINITIONS ############
include ../platform/platform.profile

################ DEPENDENCIES #########################
# depend rule must be included after the 'all' make rule

include ../platform/platform.profile.depend


clean:
	rm -f $(OBJS) $(BIN_INST)/$(PROG)


superclean:
	rm -f *~ *.D dependencies $(OBJS) $(BIN_INST)/$(PROG)

test:


# probably needs to be done by root
install:
ifndef DEVELOPER
	mkdir -p $(REAL_INST)
	install $(OWNER) $(GRP)  $(BIN_INST)/$(PROG) $(REAL_INST)
endif

uninstall:
	rm -f  $(REAL_INST)/$(PROG)

distclean: superclean

# this real rule keeps make from deleting the $(OBJS) as
# intermediate files
yangcli: $(OBJS) $(LIBTARGS)
	$(LINK) $(LN_EXTRA) $(CFLAGS) $(LFLAGS) $(OBJS) -o $(BIN_INST)/$(PROG) $(LPATH) $(MYLIBS)


.PHONY: yangcli

# prevent the make program from choking on all the symbols
# that get generated from autogenerated make rules
.NOEXPORT:

include ./dependencies
